package leetcode;

import util.TreeNode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0701.java
 * @Author : WangRuoyu
 * @Date 2023/11/15 20:58
 */


public class Q0701 {
    private void insert(TreeNode root, int val, TreeNode father, boolean left) {
        if (root == null) {
            if (left) father.left = new TreeNode(val);
            else father.right = new TreeNode(val);
        }
        if (root.val > val) {
            insert(root.left, val, root, true);
        } else {
            insert(root.right, val, root, false);
        }
    }

    public TreeNode insertIntoBST(TreeNode root, int val) {
        if (root == null) return new TreeNode(val);
        insert(root, val, null, true);
        return root;
    }

    public static void main(String[] args) {
        Q0701 sl = new Q0701();
    }
}